package com.unione.unione_base.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class DateUtil {

    public static boolean isTimeBeforeOrEqual(String startTime, String endTime) {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        Date date1 = null;
        try {
            date1 = sdf.parse(startTime);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        Date date2 = null;
        try {
            date2 = sdf.parse(endTime);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return date1.before(date2) || date1.equals(date2);
    }

    public static boolean isTimeBefore(String startTime, String endTime) {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        Date date1 = null;
        try {
            date1 = sdf.parse(startTime);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        Date date2 = null;
        try {
            date2 = sdf.parse(endTime);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return date1.before(date2);
    }

    public static String convertGMTDate(String time) {

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ");
        DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        df2.setTimeZone(TimeZone.getTimeZone("GMT"));
        Date date = null;
        try {
            date = df.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return df2.format(date);
    }
}
